package top.humbleyuan.linkedlist;

import top.humbleyuan.datastructure.linkedlist.LinkNode;

/**
 * @Author HumbleYuan
 * @Date 2020/5/18 22:03
 * @Des 两两交换链表中节点
 */
public class LeetCode_24 {
    public static void main(String[] args) {
        /**
         * 数据准备
         */
        LinkNode head = new LinkNode(1);
        int[] vals = {2,3,4};
        head = LinkNode.formLink(head,vals);


        if(head == null) {
            System.out.println("");
            return;
        }

        if(head.next == null) {
            LinkNode.headToString(head);
            return;
        }


        LinkNode pre = new LinkNode(0);
        pre.next = head;

        LinkNode f1 = pre;

        LinkNode f = head;
        while(f != null && f.next != null) {
            LinkNode f2 = f.next.next;

            f1.next = f.next;
            f.next.next = f;
            f.next = f2;

            f1 = f;
            f = f.next;
        }

        LinkNode.headToString(pre.next);
    }
}
